import time
from datetime import datetime, timedelta, timezone

print(time.time())
print(time.ctime())
timeNow = time.gmtime()

print(timeNow)

print(time.strftime("%Y-%m-%d %H:%M:%S %b %h %I", time.gmtime()))

SHA_TZ = timezone(
    timedelta(hours=8),
    name='Asia/Shanghai',
)
# 协调世界时
utc_now = datetime.utcnow().replace(tzinfo=timezone.utc)
print("UTC:")
print(utc_now, utc_now.time())
print(utc_now.date(), utc_now.tzname())
# 北京时间
beijing_now = utc_now.astimezone(SHA_TZ)

print("Beijing:")
print(beijing_now)
print(beijing_now.strftime('%Y-%m-%d %H:%M:%S'))

# 系统默认时区
local_now = utc_now.astimezone()
print("Default:")
print(local_now, local_now.time())
print(local_now.date(), local_now.tzname())

print(time.strptime("2022-4-28 10:6:20", "%Y-%m-%d %H:%M:%S"))
"""
1651112196.4294934
Thu Apr 28 10:16:36 2022
time.struct_time(tm_year=2022, tm_mon=4, tm_mday=28, tm_hour=2, tm_min=16, tm_sec=36, tm_wday=3, tm_yday=118, tm_isdst=0)
2022-04-28 02:16:36 Apr Apr 02
UTC:
2022-04-28 02:16:36.429493+00:00 02:16:36.429493
2022-04-28 UTC
Beijing:
2022-04-28 10:16:36.429493+08:00
2022-04-28 10:16:36
Default:
2022-04-28 10:16:36.429493+08:00 10:16:36.429493
2022-04-28 中国标准时间
time.struct_time(tm_year=2022, tm_mon=4, tm_mday=28, tm_hour=10, tm_min=6, tm_sec=20, tm_wday=3, tm_yday=118, tm_isdst=-1)

Process finished with exit code 0
"""